<?php
#[会员管理]
$sysnav = "user";

#[判断权限]
if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["user"])
{
	Error("对不起，您没有权限操作当前功能",$mainlink."?file=index");
}
if($sysAct == "add" || $sysAct == "modify")
{


    $job_cate=$DB->qgGetAll("SELECT * FROM ".$prefix."job_cate WHERE status=1 ORDER BY id ASC ");
    $hangye_cate=$DB->qgGetAll("SELECT * FROM ".$prefix."hangye_cate WHERE status=1 ORDER BY id ASC ");

	if($sysAct == "modify")
	{
		$id = intval($id);
		if(!$id)
		{
			Error("操作非法！",$mainlink."?file=user&act=list");
		}

		$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."user WHERE id='".$id."'");
        $content = FckToHtml($rs["company_intro"]);
        $rsd = $DB->qgGetOne("SELECT * FROM ".$prefix."upfiles WHERE id='".$rs["thumb"]."'");	#[缩略图]
	}
}
elseif($sysAct == "viewok")
{

	$id = intval($id);
	$msg = $STR->safe($_POST);

    $msg["content"] = $STR->html($msg["content"]);
	$msg["regdate"] = $msg["regdate"] ? strtotime($msg["regdate"]) : $system_time;
	if(!$msg["username"])
	{
		Error("用户名不能为空",$mainlink."?file=user&act=".($id ? "modify" : "add")."&id=".$id);
	}
	if(!$msg["password"])
	{
		Error("密码不能为空",$mainlink."?file=user&act=".($id ? "modify" : "add")."&id=".$id);
	}
	if($id)
	{
		$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."user WHERE id='".$id."'");
		$sql = "SELECT user FROM ".$prefix."user WHERE id!='".$id."' AND user='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("会员账号 ".$msg["username"]." 已经存在",$mainlink."?file=user&act=modify&id=".$id);
		}

		$password = $rs["pass"] == $msg["password"] ? $rs["pass"] : md5($msg["password"]);
        //$msg["company_intro"]= $msg["content"];
		$sql = "UPDATE ".$prefix."user SET user='".$msg["username"]."',nickname='".$msg["username"]."',realname='".$msg["realname"]."',pass='".$password."',phone='".$msg["phone"]."',email='".$msg["email"]."',address='".$msg["address"]."',postmail='".$msg["zipcode"]."',levelid='".$msg["levelid"]."',company='".$msg["company"]."',company_intro='".$msg["content"]."',company_title='".$msg["company_title"]."',hangye_id='".$msg["hangye_id"]."',thumb='".$msg["thumb"]."' WHERE id='".$id."'";

		$DB->qgQuery($sql);
		Error("会员信息更新成功",$mainlink."?file=user&act=list");
	}
	else
	{
		$sql = "SELECT user FROM ".$prefix."user WHERE user='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("会员账号 ".$msg["username"]." 已经存在",$mainlink."?file=user&act=add");
		}
		$password =md5($msg["password"]);
		
		$msg["levelid"] = $msg["levelid"] ? $msg["levelid"] : 0;

        $msg["company_intro"]= $msg["content"];
		$sql = "INSERT INTO ".$prefix."user(user,nickname,realname,pass,email,phone,address,postmail,regdate,levelid,hangye_id,thumb,company_intro) VALUES('".$msg["username"]."','".$msg["username"]."','".$msg["realname"]."','".$password."','".$msg["email"]."','".$msg["phone"]."','".$msg["address"]."','".$msg["zipcode"]."','".$system_time."',".$msg["levelid"].",'".$msg["hangye_id"]."','".$msg["thumb"]."','".$msg["content"]."')";

		$DB->qgQuery($sql);
		Error("会员信息添加成功",$mainlink."?file=user&act=list");
	}
}
elseif($sysAct == "delete")
{
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$mainlink."?file=user&act=list");
	}
	$sql = "DELETE FROM ".$prefix."user WHERE id='".$id."'";
	$DB->qgQuery($sql);
	Error("会员信息删除成功",$mainlink."?file=user&act=list");
}
elseif($sysAct == "state")
{
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$mainlink."?file=user&act=list");
	}
	$sql = "UPDATE ".$prefix."user SET state='".$state."' WHERE id='".$id."'";
	$DB->qgQuery($sql);
	Error("状态更新成功",$mainlink."?file=user&act=list");
}
elseif($act == "list")
{


	$page_url = $mainlink."?file=user&act=list";
	$psize = 30;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1=1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);

	if($keywords)
	{



	    if($stype == "company")
        {
            $condition .= " AND company LIKE '%".$keywords."%'";
        }
        elseif($stype == "phone")
        {
            $condition .= " AND phone LIKE '%".$keywords."%'";
        }

/*
		if($stype == "nickname")
		{
			$condition .= " AND nickname LIKE '%".$keywords."%'";
		}
		elseif($stype == "realname")
		{
			$condition .= " AND realname LIKE '%".$keywords."%'";
		}
		elseif($stype == "email")
		{
			$condition .= " AND email LIKE '%".$keywords."%'";
		}
		elseif($stype == "address")
		{
			$condition .= " AND address LIKE '%".$keywords."%'";
		}
		elseif($stype == "phone")
		{
			$condition .= " AND phone LIKE '%".$keywords."%'";
		}
		else
		{
			$condition .= " AND user LIKE '%".$keywords."%'";
		}*/
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}


	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."user ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT * FROM ".$prefix."user ".$condition." ORDER BY id ASC LIMIT ".$offset.",".$psize);


}









Foot("user.qg");
?>